﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SoccerEvaluator.Business;
using SoccerEvaluator.Common;
using SoccerEvaluator.WebSite.App_Code;

namespace SoccerEvaluator.WebSite
{
    /// <summary>
    /// 
    /// </summary>
    public partial class MatchStatistics : System.Web.UI.Page
    {
        /// <summary>
        /// 
        /// </summary>
        private int _projectId
        {
            get { return (int)Session["projectId"]; }
            set { Session["projectId"] = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            Template template = new Template();

            SoccerEvaluatorModelContainer context = new SoccerEvaluatorModelContainer();

            TemplateInfo projectInfo = ObjectFactory.ToTemplateInfo(context.Templates.FirstOrDefault(c => c.Id == _projectId ));

            //Si el proyecto esta en modo de juego
            if ((ProjectMode)projectInfo.ProjectMode == ProjectMode.Play)
            {
                int index = int.Parse(Request.QueryString["Index"]);

                TemplateScoreInfo s = projectInfo.Scores[index];

                List<TemplateInfo> userResults = ObjectFactory.ToTemplateInfoList(context.Templates.Where(c => c.Id == projectInfo.ID).ToList());

                Evaluator eval = new Evaluator(projectInfo.ExactScore, "96FF96", projectInfo.CatchScore, "B4B4FF");

                List<string> scores = new List<string>();
                List<string> results = new List<string>();
                List<string> others = new List<string>();

                lblMathLocation.Text = string.Format("{0}:{1}", s.Date, s.Location);

                lbMatchData.Text = string.Format("{0} {1} - {2} {3}", s.Local, s.LocalGoals, s.Visitor, s.VisitorGoals);

                //Obtiene los listados de resultados y marcadores
                eval.GetSummary(s, index, out scores, out results, out others, userResults);

                lbltotalExactScore.Text = scores.Count.ToString();
                this.lstExactScore.DataSource = scores;
                this.lstExactScore.DataBind();

                lblTotalCatchScore.Text = results.Count.ToString();
                this.lstResultScore.DataSource = results;
                this.lstResultScore.DataBind();

                lblOtherScores.Text = others.Count.ToString();
                this.lstOtherScores.DataSource = others;
                this.lstOtherScores.DataBind();
            }
        }
    }
}